#include "system.h"
#include <windows.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>

#include "struct.h"
#include "render.h"

extern char g_resPath[300];

const char* ufoGetResPath()
{
	if (!g_resPath[0]) {
		GetModuleFileName(NULL, g_resPath, 300);
		*strrchr(g_resPath, '\\') = 0;
		*strrchr(g_resPath, '\\') = 0;
		strcat(g_resPath, "\\res\\");
	}

	return g_resPath;
}

int ufoGetTouchPos(float *x, float *y)
{
	POINT pt = {0};
	GetCursorPos(&pt);
	*x = pt.x;
	*y = pt.y;
	*x /= ufoGetDPI();
    *y /= ufoGetDPI();
	return 1;
}

int ufoGetTouchState()
{
	return GetKeyState(VK_LBUTTON) & 0x8000;
}

int ufoLog(const char* tag, const char *fmt, ...)
{
	va_list	arglist;
	char buf[2048] = {0};
	char pszfinalbuf[2048] = {0};
	int len = 0;

	va_start(arglist, fmt);

	len = _vsnprintf(buf,sizeof(buf)-1, fmt, arglist);

	va_end(arglist);
	if (len >= 2048)
		buf[2047] = '\0'; 

	_snprintf(pszfinalbuf, sizeof(buf)-1, "%s: %s\n", tag, buf);

	OutputDebugStringA(pszfinalbuf);

	return 1;
}

float ufoGetDPI()
{
	return 1.0f;
}